<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/03/14
// +----------------------------------------------------------------------
namespace app\erp\behavior\coupon_receive_before;

/**
 * 优惠券是否发完
 * @package app\user_center\behavior\user
 * @author shiqiang
 */
class isFinished{
    /**
     * 执行行为 run方法是Behavior唯一的接口
     * @access public
     * @return void
     */
    public function run($params){
    	$user_id   = $params['user_id'];
    	$coupon_id = $params['coupon_id'];
		
		$map = [];
		$map[] = ['coupon_id', '=', $coupon_id];
		$map[] = ['coupon_user', '>', 0];
		$receive_count = model('erp/ErpCouponUseinfo', 'model') -> where($map) -> count(); //领取数量
		
		$coupon_info = model('erp/ErpCoupon', 'model') -> find($coupon_id);//优惠券信息
		if($coupon_info['coupon_sum'] <= $receive_count){
			return array_out(-1002, '已经发完了');
		}
    }
}
